<?php

namespace app\api\behavior;

use think\facade\Request;

class Cors
{
    /**
     * 跨域配置
     *
     * @return [type] [description]
     */
    public function appInit()
    {
        $header = Request::header();

        header('Content-Type: text/html;charset=utf-8');
        header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Headers: *");
        header('Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE');
        header('Access-Control-Allow-Credentials: true');
        if (!empty($header['origin'])) {
            header('Access-Control-Allow-Origin: '.$header['origin']);
        }
    }
}
